package seunit.framework.automation;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class locator {
	WebDriver driver;
	public locator(WebDriver _driver){
		this.driver = _driver;
	}
	public WebElement getElement(String locate){
		locate = locate.toLowerCase();
		if(locate.startsWith("name="))
		{
			locate = locate.replace("name=", "");
			return driver.findElement(By.name(locate));
		}
		if(locate.startsWith("xpath=") || locate.startsWith("//"))
		{
			locate = locate.replace("xpath=", "");
			return driver.findElement(By.xpath(locate));
		}
		if(locate.startsWith("css="))
		{
			locate = locate.replace("css=", "");
			return driver.findElement(By.cssSelector(locate));
		}
		if(locate.startsWith("class="))
		{
			locate = locate.replace("class=", "");
			return driver.findElement(By.className(locate));
		}
		if(locate.startsWith("link="))
		{
			locate = locate.replace("link=", "");
			return driver.findElement(By.linkText(locate));
		}
		if(locate.startsWith("id="))
		{
			locate = locate.replace("id=", "");
			return driver.findElement(By.id(locate));
		}
		
		return driver.findElement(By.id(locate));
	}
	
	public String getFormatedXpath(String locate){
		
		
		return locate;
	}
}
